﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPMS.Log.Formatter;
using SPMS.Log.Core;

namespace SPMS.Log.Utility
{
    /// <summary>
    /// 通用日志适配器
    /// </summary>
    /// <remarks>用于将日志框架的日志输出器与通用日志的日志输出器进行适配</remarks>
    /// <history>
    /// [zanezeng]               2009/9/30 15:00    创建
    /// </history>
    public sealed class CommonLogAdapter : Commons.Logging.ILog
    {
        #region ---Constructor

        /// <summary>
        /// 初始化类型<see cref="CommonLogAdapter"/>的新实例
        /// </summary>
        /// <param name="logger">要适配到通用日志框架日志对象上的日志记录器</param>
        /// <remarks></remarks>
        /// <exception cref="ArgumentNullException"><paramref name="logger"/>为Null</exception>
        /// <history>
        /// [zanezeng]               2009/9/30 15:56    创建
        /// </history>
        public CommonLogAdapter( ILogger logger )
        {
            //断言参数
            if (null == logger)
            {
                //抛出异常
                throw new ArgumentNullException( "logger" );
            }

            //保存参数
            this.m_AdaptedLogger = logger;
        }

        #endregion

        #region ---SPMS.Commons.Logging.ILog

        /// <summary>
        /// 根据当前日志级别设定判断是否允许输出调试级别日志信息
        /// </summary>
        /// <value>
        /// 	<c>true</c>允许<br/>
        /// 	<c>false</c>不允许
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:23 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:02    创建
        /// </history>
        public bool IsDebugEnabled
        {
            get
            {
                return this.m_AdaptedLogger.IsLevelEnabled( Level.Debug );
            }
        }

        /// <summary>
        /// 根据当前日志级别设定判断是否允许输出跟踪级别日志信息
        /// </summary>
        /// <value>
        /// 	<c>true</c>允许<br/>
        /// 	<c>false</c>不允许
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:19 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:02    创建
        /// </history>
        public bool IsTraceEnabled
        {
            get
            {
                return this.m_AdaptedLogger.IsLevelEnabled( Level.Trace );
            }
        }

        /// <summary>
        /// 根据当前日志级别设定判断是否允许输出提示级别日志信息
        /// </summary>
        /// <value>
        /// 	<c>true</c>允许<br/>
        /// 	<c>false</c>不允许
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:24 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:02    创建
        /// </history>
        public bool IsInfoEnabled
        {
            get
            {
                return this.m_AdaptedLogger.IsLevelEnabled( Level.Info );
            }
        }

        /// <summary>
        /// 根据当前日志级别设定判断是否允许输出警告级别日志信息
        /// </summary>
        /// <value>
        /// 	<c>true</c>允许<br/>
        /// 	<c>false</c>不允许
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:25 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:02    创建
        /// </history>
        public bool IsWarnEnabled
        {
            get
            {
                return this.m_AdaptedLogger.IsLevelEnabled( Level.Warn );
            }
        }

        /// <summary>
        /// 根据当前日志级别设定判断是否允许输出错误级别日志信息
        /// </summary>
        /// <value>
        /// 	<c>true</c>允许<br/>
        /// 	<c>false</c>不允许
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:25 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:02    创建
        /// </history>
        public bool IsErrorEnabled
        {
            get
            {
                return this.m_AdaptedLogger.IsLevelEnabled( Level.Error );
            }
        }

        /// <summary>
        /// 根据当前日志级别设定判断是否允许输出灾难级别日志信息
        /// </summary>
        /// <value>
        /// 	<c>true</c>允许<br/>
        /// 	<c>false</c>不允许
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:25 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:03    创建
        /// </history>
        public bool IsFatalEnabled
        {
            get
            {
                return this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal );
            }
        }

        /// <summary>
        /// 判断当前日志记录器是否允许输出给定日志级别的日志
        /// </summary>
        /// <param name="level">用于判定的日志级别</param>
        /// <returns>
        /// 	<c>true</c>：允许输出<br/>
        /// 	<c>false</c>：不允许输出
        /// </returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/24 13:30    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:03    创建
        /// </history>
        public bool IsLevelEanbled( SPMS.Commons.Logging.LogLevelEnum level )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断适配的日志框架日志是否允许
            return this.m_AdaptedLogger.IsLevelEnabled( mappedLevel );
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">要输出的日志信息的级别</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:06    创建
        /// </history>
        public void WriteLog( SPMS.Commons.Logging.LogLevelEnum level, object message )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( mappedLevel ))
            {
                //输出日志
                this.WriteLogInternal( mappedLevel, message );
            }
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">要输出的日志信息的级别</param>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:26    创建
        /// </history>
        public void WriteLog( SPMS.Commons.Logging.LogLevelEnum level, Exception ex, object message )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( mappedLevel ))
            {
                //输出日志
                this.WriteLogInternal( mappedLevel, message, ex );
            }
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">要输出的日志信息的级别</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:27    创建
        /// </history>
        public void WriteLog( SPMS.Commons.Logging.LogLevelEnum level, string message, params object[] args )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( mappedLevel ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( mappedLevel, formattedMessage );
            }
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">要输出的日志信息的级别</param>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:29    创建
        /// </history>
        public void WriteLog( SPMS.Commons.Logging.LogLevelEnum level, Exception ex, string message, params object[] args )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( mappedLevel ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( mappedLevel, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">要输出的日志信息的级别</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:29    创建
        /// </history>
        public void WriteLog( SPMS.Commons.Logging.LogLevelEnum level, IFormatProvider provider, string message, params object[] args )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( mappedLevel ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( mappedLevel, formattedMessage );
            }
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">要输出的日志信息的级别</param>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:30    创建
        /// </history>
        public void WriteLog( SPMS.Commons.Logging.LogLevelEnum level, Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //获得对应的日志框架级别
            Level mappedLevel = GetMappedLevel( level );

            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( mappedLevel ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( mappedLevel, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出调试信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:30    创建
        /// </history>
        public void Debug( object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Debug ))
            {
                //输出日志
                this.WriteLogInternal( Level.Debug, message );
            }
        }

        /// <summary>
        /// 输出调试信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:31    创建
        /// </history>
        public void Debug( Exception ex, object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Debug ))
            {
                //输出日志
                this.WriteLogInternal( Level.Debug, message, ex );
            }
        }

        /// <summary>
        /// 输出调试信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:31    创建
        /// </history>
        public void Debug( string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Debug ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Debug, formattedMessage );
            }
        }

        /// <summary>
        /// 输出调试信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:31    创建
        /// </history>
        public void Debug( Exception ex, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Debug ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Debug, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出调试信息
        /// </summary>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:32    创建
        /// </history>
        public void Debug( IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Debug ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Debug, formattedMessage );
            }
        }

        /// <summary>
        /// 输出调试信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:32    创建
        /// </history>
        public void Debug( Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Debug ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Debug, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出跟踪信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:32    创建
        /// </history>
        public void Trace( object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Trace ))
            {
                //输出日志
                this.WriteLogInternal( Level.Trace, message );
            }
        }

        /// <summary>
        /// 输出跟踪信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:32    创建
        /// </history>
        public void Trace( Exception ex, object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Trace ))
            {
                //输出日志
                this.WriteLogInternal( Level.Trace, message, ex );
            }
        }

        /// <summary>
        /// 输出跟踪信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:33    创建
        /// </history>
        public void Trace( string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Trace ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Trace, formattedMessage );
            }
        }

        /// <summary>
        /// 输出跟踪信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:33    创建
        /// </history>
        public void Trace( Exception ex, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Trace ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Trace, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出跟踪信息
        /// </summary>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:33    创建
        /// </history>
        public void Trace( IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Trace ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Trace, formattedMessage );
            }
        }

        /// <summary>
        /// 输出跟踪信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:34    创建
        /// </history>
        public void Trace( Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Trace ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Trace, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出提示信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:34    创建
        /// </history>
        public void Info( object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Info ))
            {
                //输出日志
                this.WriteLogInternal( Level.Info, message );
            }
        }

        /// <summary>
        /// 输出提示信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:34    创建
        /// </history>
        public void Info( Exception ex, object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Info ))
            {
                //输出日志
                this.WriteLogInternal( Level.Info, message, ex );
            }
        }

        /// <summary>
        /// 输出提示信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:34    创建
        /// </history>
        public void Info( string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Info ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Info, formattedMessage );
            }
        }

        /// <summary>
        /// 输出提示信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:35    创建
        /// </history>
        public void Info( Exception ex, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Info ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Info, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出提示信息
        /// </summary>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:35    创建
        /// </history>
        public void Info( IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Info ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Info, formattedMessage );
            }
        }

        /// <summary>
        /// 输出提示信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:35    创建
        /// </history>
        public void Info( Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Info ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Info, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出警告信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:35    创建
        /// </history>
        public void Warn( object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Warn ))
            {
                //输出日志
                this.WriteLogInternal( Level.Warn, message );
            }
        }

        /// <summary>
        /// 输出警告信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:36    创建
        /// </history>
        public void Warn( Exception ex, object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Warn ))
            {
                //输出日志
                this.WriteLogInternal( Level.Warn, message, ex );
            }
        }

        /// <summary>
        /// 输出警告信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:36    创建
        /// </history>
        public void Warn( string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Warn ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Warn, formattedMessage );
            }
        }

        /// <summary>
        /// 输出警告信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:36    创建
        /// </history>
        public void Warn( Exception ex, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Warn ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Warn, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出警告信息
        /// </summary>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:36    创建
        /// </history>
        public void Warn( IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Warn ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Warn, formattedMessage );
            }
        }

        /// <summary>
        /// 输出警告信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:36    创建
        /// </history>
        public void Warn( Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Warn ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Warn, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:37    创建
        /// </history>
        public void Error( object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Error ))
            {
                //输出日志
                this.WriteLogInternal( Level.Error, message );
            }
        }

        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:37    创建
        /// </history>
        public void Error( Exception ex, object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Error ))
            {
                //输出日志
                this.WriteLogInternal( Level.Error, message, ex );
            }
        }

        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:37    创建
        /// </history>
        public void Error( string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Error ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Error, formattedMessage );
            }
        }

        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:37    创建
        /// </history>
        public void Error( Exception ex, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Error ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Error, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:37    创建
        /// </history>
        public void Error( IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Error ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Error, formattedMessage );
            }
        }

        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:37    创建
        /// </history>
        public void Error( Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Error ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Error, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出灾难信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:38    创建
        /// </history>
        public void Fatal( object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal ))
            {
                //输出日志
                this.WriteLogInternal( Level.Fatal, message );
            }
        }

        /// <summary>
        /// 输出灾难信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:40    创建
        /// </history>
        public void Fatal( Exception ex, object message )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal ))
            {
                //输出日志
                this.WriteLogInternal( Level.Fatal, message, ex );
            }
        }

        /// <summary>
        /// 输出灾难信息
        /// </summary>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:39    创建
        /// </history>
        public void Fatal( string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Fatal, formattedMessage );
            }
        }

        /// <summary>
        /// 输出灾难信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:39    创建
        /// </history>
        public void Fatal( Exception ex, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( null, message, args );

                //输出日志
                this.WriteLogInternal( Level.Fatal, formattedMessage, ex );
            }
        }

        /// <summary>
        /// 输出灾难信息
        /// </summary>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:39    创建
        /// </history>
        public void Fatal( IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Fatal, formattedMessage );
            }
        }

        /// <summary>
        /// 输出灾难信息
        /// </summary>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <param name="provider">用于消息格式化的格式化提供者</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="args">输出信息的格式化参数</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   9/6/2008 9:30 AM    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/30 15:23    创建
        /// </history>
        public void Fatal( Exception ex, IFormatProvider provider, string message, params object[] args )
        {
            //判断是否允许输出
            if (this.m_AdaptedLogger.IsLevelEnabled( Level.Fatal ))
            {
                //格式化消息
                object formattedMessage = this.FormatMessage( provider, message, args );

                //输出日志
                this.WriteLogInternal( Level.Fatal, formattedMessage, ex );
            }
        }

        #endregion

        #region ---Private Method

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">日志的级别</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/24 9:23    创建
        /// </history>
        private void WriteLogInternal( Level level, object message )
        {
            this.WriteLogInternal( level, message, null );
        }

        /// <summary>
        /// 输出日志信息
        /// </summary>
        /// <param name="level">日志的级别</param>
        /// <param name="message">需要输出到日志的信息</param>
        /// <param name="ex">需要输出到日志的异常对象</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/24 9:23    创建
        /// </history>
        private void WriteLogInternal( Level level, object message, Exception ex )
        {
            //判断日志级别是否允许输出
            if (!this.m_AdaptedLogger.IsLevelEnabled( level ))
            {
                //如果不允许，则直接返回
                return;
            }

            try
            {
                //创建执行点
                ExecutingLocation location = new ExecutingLocation( TYPE_STACKBOUNDARY );

                //创建日志记录对象
                LogEntry entry = new LogEntry( location, this.m_AdaptedLogger.Name, level, message, ex );

                //写入日志
                this.m_AdaptedLogger.WriteLog( entry );
            }
            catch (Exception exception)
            {
                //输出日志
                if (LoggingContext.MetaLog.IsErrorEnabled)
                {
                    LoggingContext.MetaLog.Error( exception, "日志记录器'{0}'写入日志失败", this.m_AdaptedLogger.Name );
                }
            }
        }

        /// <summary>
        /// 格式化字符串消息
        /// </summary>
        /// <param name="provider">字符串格式化提供者</param>
        /// <param name="message">消息的复合格式字符串</param>
        /// <param name="args">包含零个或多个要格式化的对象的<see cref="System.Object"/>数组</param>
        /// <returns><paramref name="message"/>的一个副本，其中的第一个格式项已替换为<paramref name="args"/>中相应<see cref="System.Object"/>实例的<see cref="System.String"/>等效项</returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/24 13:47    创建
        /// </history>
        private string FormatMessage( IFormatProvider provider, string message, params  object[] args )
        {
            try
            {
                //判断要格式化的消息是否为NULL或者为空字符串
                if (string.IsNullOrEmpty( message ))
                {
                    //如果要格式化的消息为NULL或者为空字符串，则不需要进行格式化
                    return message;
                }

                //判断是否提供了字符串格式化提供者
                if (null == provider)
                {
                    //格式化字符串
                    return string.Format( message, args );
                }
                else
                {
                    //使用格式化提供器格式化
                    return string.Format( provider, message, args );
                }
            }
            catch (Exception ex)
            {
                //输出日志
                if (LoggingContext.MetaLog.IsErrorEnabled)
                {
                    LoggingContext.MetaLog.Error( ex, "格式化日志消息'{0}'的过程中发生异常，格式化日志消息失败", message );
                }

                //返回消息模板
                return message;
            }
        }

        /// <summary>
        /// 获得日志框架中与通用日志框架级别对应的日志级别
        /// </summary>
        /// <param name="level">要获得对应日志框架级别的通用日志框架级别</param>
        /// <returns>日志框架中与通用日志框架级别对应的日志级别</returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/16 15:19    创建
        /// </history>
        private static Level GetMappedLevel( Commons.Logging.LogLevelEnum level )
        {
            //根据日志级别的名称检索日志对象
            switch (level)
            {
                case Commons.Logging.LogLevelEnum.All:
                    //全部输出日志级别
                    return Level.All;

                case Commons.Logging.LogLevelEnum.Trace:
                    //跟踪日志级别
                    return Level.Trace;

                case Commons.Logging.LogLevelEnum.Debug:
                    //调试日志级别
                    return Level.Debug;

                case Commons.Logging.LogLevelEnum.Info:
                    //提示信息日志级别
                    return Level.Info;

                case Commons.Logging.LogLevelEnum.Warn:
                    //警告信息级别
                    return Level.Warn;

                case Commons.Logging.LogLevelEnum.Error:
                    //错误信息日志级别
                    return Level.Error;

                case Commons.Logging.LogLevelEnum.Fatal:
                    //严重错误信息级别
                    return Level.Fatal;

                case Commons.Logging.LogLevelEnum.Off:
                    //关闭日志输出
                    return Level.Off;

                default:
                    //默认返回默认日志级别
                    return Level.All;
            }
        }

        #endregion

        #region ---Field

        /// <summary>
        /// 适配的日志框架日志对象
        /// </summary>
        private ILogger m_AdaptedLogger;

        /// <summary>
        /// 堆栈分界类型
        /// </summary>
        private Type TYPE_STACKBOUNDARY = typeof( CommonLogAdapter );

        #endregion
    }
}
